package com.game.HUD;

import media.sound.GameSound;

import com.game.R;

import object.obj2D.graphics.TexSquare;
import object.obj2D.graphics.Texture;
import system.GameOption;

public class ShowYouWin extends ShowGUIItem {
	
	
	static private int m_youWinWidth = 512;
	static private int m_youWinHeight = 128;
	static private int m_iYouWinID;
	static private TexSquare m_youWinSquare;
	static private long m_iYouWinStartTime;
	static private boolean m_isDisplayYouWin = false;
	static private float m_alphaWin = 1.0f;
	
	static private int DISPLAY_YOUWIN_TIME = 2000;
	static private long  m_youWinStartTime;
	static private int UPDATE_ALPHA_YOUWIN_TIME = 50;
	static private long m_lastTimeAlphaYouWin;
	static private boolean m_isStartAlphaYouWin = false;
	static private boolean m_isStartYouWin = false;
	private static Texture m_texture;
	
	public static void Init()
	{
		m_texture = new Texture();
		
		m_iYouWinID = m_texture.initTexture(R.drawable.you_win);
		m_youWinSquare = new TexSquare(m_youWinWidth, m_youWinHeight);
	}
	
	public static void Render()
	{
		if(m_isDisplayYouWin)
		{
			m_texture.loadTexture(m_iYouWinID);
			m_youWinSquare.Render();
		}
	}
	
	public static boolean isWin()
	{
		return m_isDisplayYouWin;
	}
	
	public static void Update()
	{
		if(s_level.GetTotalAliveEnemyHP() == 0)
		{
			m_iYouWinStartTime  = System.nanoTime();
			m_isStartYouWin = true;
		}
		
		if(m_isStartYouWin && !m_isDisplayYouWin && (System.nanoTime() - m_iYouWinStartTime)/1000000 > 3000) 
		{
			m_isDisplayYouWin = true;
			if(GameOption.isMusicOn) GameSound.GetBgSound().Stop();
			m_youWinStartTime = System.nanoTime();
		}
		
		if(m_isDisplayYouWin)
		{
			if(!m_isStartAlphaYouWin && (System.nanoTime() - m_youWinStartTime)/1000000 >= DISPLAY_YOUWIN_TIME)
			{
				m_isStartAlphaYouWin = true;
				m_lastTimeAlphaYouWin = System.nanoTime();
			}
			
			if(m_isStartAlphaYouWin)
			{
				if(m_alphaWin >= 0f && (System.nanoTime() - m_lastTimeAlphaYouWin)/1000000 > UPDATE_ALPHA_YOUWIN_TIME)
				{
					m_alphaWin -= 0.05f;
					m_lastTimeAlphaYouWin = System.nanoTime();
				}
			}
		}
	}
}
